
//
//  binDetailTableViewController.swift
//  Wmsmobile
//
//  Created by Nick xu on 16/8/19.
//  Copyright © 2016年 www.hd123.com. All rights reserved.
//

import UIKit

class chkBinRtnArtController: UITableViewController {
    
    //MARK: - property
    var info: [String : String]?
    let dataArray = ["货品代码","货品名称","规格","件数","数量","单位","批号","到效期","收货日期","收货单号","重量"]
    
    init(){
        super.init(style: UITableViewStyle.plain)
    }
    convenience init(info: [String : String]){
        self.init()
        self.info = info
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.register(binDetailCell.self, forCellReuseIdentifier: "binDetailCell")
        
    }
    
    
    // MARK: - Table view data source
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray.count
        
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "binDetailCell") as! binDetailCell
        let title =  dataArray[(indexPath as NSIndexPath).row]
        var info = ["title" : title]
        switch title {
        case "货品代码":
            info.updateValue(self.info!["代码"] ?? "", forKey: "detail")
            info.updateValue("calendar-2", forKey: "icon")
        case "货品名称":
            info.updateValue(self.info!["品名"] ?? "", forKey: "detail")
        case "重量":
            info.updateValue(self.info!["单品重量"] ?? "", forKey: "detail")
        case "到效期":
            let string = String(self.info!["到效期"] ?? "0")
            let array = string?.components(separatedBy: " ")
            let stringFinal = array?.first?.replacingOccurrences(of: "/", with: "-")
            info.updateValue(stringFinal ?? "", forKey: "detail")
        case "收货日期":
            let string = String(self.info!["收货日期"] ?? "0")
            let array = string?.components(separatedBy: " ")
            let stringFinal = array?.first?.replacingOccurrences(of: "/", with: "-")
            info.updateValue(stringFinal ?? "", forKey: "detail")
        default:
            info.updateValue(self.info![title] ?? "", forKey: "detail")
        }
        cell.info = info
        return cell
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    
}
